/**
 * 北京中流科技有限公司 版权所有
 * http://www.chinasoa.com.cn
 */
package cn.com.chinasoa.cms.portlet.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import org.w3c.dom.Element;

import com.x4ee.soa.portal.framework.core.ActionConfig;
import com.x4ee.soa.portal.framework.core.ActionFilter;
import com.x4ee.soa.portal.framework.core.BaseRequestFilter;
import com.x4ee.soa.portal.framework.core.FrameworkConfig;

/**
 * @author 刘洋(liuyang@chinasoa.com.cn)
 * 2007-8-7上午11:55:24
 */
public class URIDeleteActionFilter extends BaseRequestFilter implements
		ActionFilter {
	private FrameworkConfigWraper tFrameworkConfigWraper =null;
	public String process(ActionRequest actionRequest, ActionResponse actionResponse,
			ActionConfig actionConfig) throws PortletException, IOException {
		String urn = actionRequest.getParameter(FrameworkConfigWraper.FRAMEWORK_URN_URN);
		if(urn!=null){
			tFrameworkConfigWraper.removeUri(urn);
			//URI Map
			Map frameworkUriMap = new HashMap();
			Map uriMap = FrameworkConfigWraper.getURIMapByRenderName(tFrameworkConfigWraper.getXmlConfig(),"ViewIndex");
			for(Iterator rIt = uriMap.keySet().iterator();rIt.hasNext();){
				Object keyObj = rIt.next();
				if((keyObj!=null)&&(keyObj instanceof String)){
					String key = (String)keyObj;
					Object valueObj = uriMap.get(keyObj);			
					if((valueObj!=null)&&(valueObj instanceof String)){
						String mValue = (String)valueObj;
						if(mValue.indexOf("jsp/")>-1){
							String tValue= mValue.substring(mValue.lastIndexOf("jsp/")+4, mValue.length());
							frameworkUriMap.put(key, tValue);
						}
					}
				}
			}
			actionRequest.getPortletSession().setAttribute(FrameworkConfigWraper.FRAMEWORK_URI_MAP,frameworkUriMap);
			Map frameworkOutletMap = FrameworkConfigWraper.getOutletMapByRenderName(tFrameworkConfigWraper.getXmlConfig(),"ViewIndex");
			actionRequest.getPortletSession().setAttribute(FrameworkConfigWraper.FRAMEWORK_OUTLET_MAP,frameworkOutletMap);			
		}
		return FrameworkConfigWraper.DEFAULT;
	}
	public void init(Element tXmlConfig, FrameworkConfig frameworkConfig) throws PortletException {
		super.init(tXmlConfig, frameworkConfig);
		tFrameworkConfigWraper = new FrameworkConfigWraper(tXmlConfig,frameworkConfig);		
	}
}
